<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='splm'/></label>
                        <div class="layui-input-inline">

                            <select lay-verify="required" id="topChannel" lay-filter="topChannel" name="goodsChannel.parent.parent.id">
                                <option value="0"><fmt:message key='qxz'/></option>
                                <c:forEach items="${channels }" var="item">
                                    <option value="${item.id}"
                                            <c:if test="${item.id eq params.goodsChannel.parent.parent.id}">selected="selected"</c:if> >${item.name}</option>
                                </c:forEach>
                            </select>
                        </div>

                        <div class="layui-input-inline middleChannel">
                            <select lay-verify="required" id="middleChannel" lay-filter="middleChannel" name="goodsChannel.parent.id">
                                <option value="0"><fmt:message key='qxz'/></option>
                                <c:forEach items="${params.goodsChannel.parent.parent.children }" var="item">
                                    <option value="${item.id}"
                                            <c:if test="${item.id eq params.goodsChannel.parent.id}">selected="selected"</c:if>>${item.name}
                                    </option>
                                </c:forEach>
                            </select>
                        </div>

                        <div class="layui-input-inline bottomChannel">
                            <select lay-verify="required" name="goodsChannel.id" id="bottomChannel" lay-filter="bottomChannel">
                                <option value="0"><fmt:message key='qxz'/></option>
                                <c:forEach items="${params.goodsChannel.parent.children }" var="item">
                                    <option value="${item.id}"
                                            <c:if test="${item.id eq params.goodsChannel.id}">selected="selected"</c:if> >${item.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss'/></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">

            <table class="layui-table layui-form" lay-size="sm">
                <thead>
                <tr>
                    <th></th>
                    <th><fmt:message key='xh'/></th>
                    <th><fmt:message key='lmmc'/></th>
                    <th><fmt:message key='ssjb'/></th>
                </tr>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td><input type="checkbox" value="${item.id}" data-level="${item.level}" data-name="${item.name}" class="feijin-check" lay-ignore lay-skin="primary"/></td>
                        <td>${status.index + 1 }</td>
                        <td>${item.name}</td>
                        <td>
                            <c:if test="${item.level == 1}"><fmt:message key='yj'/></c:if>
                            <c:if test="${item.level == 2}"><fmt:message key='ej'/></c:if>
                            <c:if test="${item.level == 3}"><fmt:message key='sj1'/></c:if>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>


    layui.use(['form', 'laydate'], function () {

        var form = layui.form;

        $("input[type=checkbox]").change(function () {
            if (this.checked) {
                $(this).parent().parent().siblings().find("input[type=checkbox]").prop("checked", false);
            }
        });

        //加载二级商品类目
        form.on('select(topChannel)', function (data) {
            if (data.elem != data.value) {
                var id = $("#topChannel").val();
                $(".middleChannel").html("");
                $(".bottomChannel").html("");

                $.ajax({
                    url: "${web_domain}/mall/goods/childChannels?id=" + id,
                    type: "get",
                    dataType: "JSON",
                    success: function (result) {
                        if (result.status && result.result != null) {
                            var channelsHTML = "<select lay-verify='required' id='middleChannel' class='layui-input' lay-filter='middleChannel' name='goodsChannel.parent.id'>" +
                                "<option value='0'><fmt:message key='qxz'/></option>";
                            $.each(result.result, function (index, item) {
                                channelsHTML += "<option value='" + item.id + "' >" + item.name + "</option>"
                            });
                            channelsHTML += "</select>";

                            $(".middleChannel").html(channelsHTML);
                            form.render('select');//重新渲染
                        }
                    }
                });
            }
        });

        //加载三级商品类目
        form.on('select(middleChannel)', function (data) {
            if (data.elem != data.value) {
                var id = $("#middleChannel").val();
                $(".bottomChannel").html("");

                $.ajax({
                    url: "${web_domain}/mall/goods/childChannels?id=" + id,
                    type: "get",
                    dataType: "JSON",
                    success: function (result) {
                        if (result.status && result.result != null) {
                            var channelsHTML = "<select lay-verify='required' name='goodsChannel.id' id='bottomChannel' class='layui-input' lay-filter='bottomChannel'>" +
                                "<option value='0'><fmt:message key='qxz'/></option>";
                            $.each(result.result, function (index, item) {
                                channelsHTML += "<option value='" + item.id + "' >" + item.name + "</option>"
                            });
                            channelsHTML += "</select>";
                            $(".bottomChannel").html(channelsHTML);
                            form.render('select');//重新渲染
                        }
                    }
                });
            }
        });


    });

</script>
</body>
</fmt:bundle>
</html>
